package com.org.oracle.controller;

import com.org.oracle.mongodb.dto.PostgraduateRequestDTO;
import com.org.oracle.result.Result;
import com.org.oracle.service.impl.PostgraduateAssistantService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;

@RestController
@RequestMapping("/postgraduate")
public class PostgraduateController {
    private final PostgraduateAssistantService assistantService;

    public PostgraduateController(PostgraduateAssistantService assistantService) {
        this.assistantService = assistantService;
    }

    @PostMapping("/assist")
    public Mono<ResponseEntity<Result>> assist(
        @RequestBody PostgraduateRequestDTO request) {
        
        return assistantService.handleRequest(request)
            .map(response -> ResponseEntity.ok(Result.ok(response)))
            .onErrorResume(e -> Mono.just(
                ResponseEntity.ok(Result.fail("助手服务异常"))
            ));
    }
}